package com.shu.project.service.impl;

import com.shu.project.controller.LoginController;
import com.shu.project.dao.GoodsDao;
import com.shu.project.dao.OrderDao;
import com.shu.project.dao.SeckillGoodsDao;
import com.shu.project.model.Goods;
import com.shu.project.model.Order;
import com.shu.project.model.User;
import com.shu.project.service.IGoodsService;
import com.shu.project.service.IOrderService;
import com.shu.project.service.ISeckillService;
import com.shu.project.vo.GoodsVo;
import com.shu.project.vo.OrderVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("seckillService")
public class SeckillServiceImpl implements ISeckillService {
    private static final Logger log = LoggerFactory.getLogger(SeckillServiceImpl.class);

    @Autowired
    IGoodsService goodsService;
    @Autowired
    IOrderService orderService;
    @Transactional
    @Override
    public Order seckill(User user, GoodsVo goodsVo) {
        //减少库存  下订单，写入秒杀订单

        boolean isok=goodsService.reduceStock(goodsVo.getId());
        log.info("库存减成功{]",isok);
        return orderService.createOrder(user,goodsVo);
    }
}
